package com.yanqu.road.server.cmd.chefduel.process2.cross;

import com.yanqu.road.entity.activity.chefduel.ChefDuelData;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.logic.activity.chefduel.ChefDuel2Config;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.chefduel.ChefDuelProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.activity.chefduel.ChefDuelActivityMgr;
import com.yanqu.road.server.manger.activity.chefduel.ChefDuelMgr;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_CHEF_DUEL2_CAMP_RANK_REWARD_FROM_CROSS, desc = "阵营排行奖励(跨服返回)")
public class ChefDuel2CampGetRankRewardFromCrossCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ChefDuelProto.CrossChefDuelGetCampRankRewardRespMsg respMsg = ChefDuelProto.CrossChefDuelGetCampRankRewardRespMsg.parseFrom(packet.getBytes());
        if(respMsg.getRet() == 0) {
            ChefDuel2Config chefDuel2Config = ChefDuelActivityMgr.getChefDuel2Config(respMsg.getActivityId());
            if(chefDuel2Config != null){
                ChefDuelData duelData = ChefDuelMgr.getUserChefDuel2DataNoLock(respMsg.getActivityId(), player);
                if (duelData != null && duelData.getCampRewardGet() == 0) {
                    duelData.setCampRewardGet(1);
                    if(respMsg.getRank() > 0){
                        String reward = chefDuel2Config.getCHEFDUEL2_TEAM_WIN_REWARD();
                        if(respMsg.getRank() == 2){
                            reward = chefDuel2Config.getCHEFDUEL2_TEAM_LOSE_REWARD();
                        }
                        player.getModule(CurrencyModule.class).addCurrency(reward, eLogMoneyType.ChefDuel, eLogMoneyType.CrossChefDuel2CampRankReward);

                        ChefDuelProto.ChefDuelGetCampRankRewardRespMsg.Builder clientMsg = ChefDuelProto.ChefDuelGetCampRankRewardRespMsg.newBuilder();
                        clientMsg.setRet(0);
                        clientMsg.setReward(reward);
                        player.sendPacket(Protocol.U_CHEF_DUEL2_CAMP_RANK_REWARD, clientMsg);
                    }
                }
            }
        }
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
